<template>
  <div class="content">
    <div style="float: left">
      <el-button @click="turnUpdate" size="small">上报</el-button>
    </div>

    <div style="float: right">
      <el-input
        v-model="obj.province"
        placeholder="请输入要查询的省份"
      ></el-input>
    </div>

    <el-table
      :data="dataList.list"
      :default-sort="{ prop: 'id', order: 'descending' }"
      style="width: 100%; magin-bottom: 5"
    >
      <el-table-column
        fixed="left"
        align="center"
        prop="id"
        label="编号"
        width="80"
        sortable
      >
      </el-table-column>
      <el-table-column align="center" prop="country" label="国家">
      </el-table-column>
      <el-table-column align="center" prop="province" label="省份">
      </el-table-column>
      <el-table-column align="center" prop="city" label="市"> </el-table-column>
      <el-table-column align="center" prop="area" label="区"> </el-table-column>
      <el-table-column align="center" prop="confirmed" label="现有确诊">
      </el-table-column>
      <el-table-column align="center" prop="suspected" label="疑似">
      </el-table-column>
      <el-table-column align="center" prop="dead" label="死亡">
        <template v-slot="scope">
          <el-tag type="danger">{{ scope.row.dead }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="cure" label="治愈">
        <template v-slot="scope">
          <el-tag type="success">{{ scope.row.cure }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="severe" label="累计确诊">
      </el-table-column>
      <el-table-column align="center" prop="outside" label="境外输入">
      </el-table-column>
      <el-table-column
        fixed="right"
        align="center"
        prop="inputTime"
        label="录入时间"
        sortable
        width="180"
        ><template v-slot="scope">
          <div>{{ scope.row.inputTime | dateFMT }}</div>
        </template>
      </el-table-column>
    </el-table>

    <div style="width: 80%; text-align: center">
      <el-pagination
        layout="prev, pager, next"
        :total="dataList.total"
        :page-size="obj.pageSize"
        :current-page="obj.page"
        @current-change="change_page"
      >
      </el-pagination>
    </div>
    <div>
      
      <div style="float:left;margin-right:20px;">
        <el-input v-model="deId"  placeholder="请输入要删除的编号" style="width:150px;"></el-input>
      </div>

      <div style="float:left;"><el-button @click="delete_Id"   size="small">删除</el-button></div>
    </div>
  </div>
</template>



<script>
// 从vuex中导入辅助函数
// 辅助函数:帮助我们快速获取状态机中的变量或方法
import { mapActions, mapState } from "vuex";
export default {
  // 计算属性
  computed: {
    // 从dataList.js文件的state中获取dataList变量
    ...mapState("dataList", ["dataList"]),
  },
  data() {
    return {
      obj: {
        page: 1,
        pageSize: 10,
      },
      total: 100,
      deId:''
    };
  },
  created() {
    this.page_query(this.obj);
  },
  watch: {
    obj: {
      handler: function () {
        this.page_query(this.obj);
      },
      deep: true,
    },
  },
  
  methods: {
    // 从dataList.js文件的action中获取page_query方法
    ...mapActions("dataList", ["page_query","deleteById"]),
    // 删除文章
    delete_Id() {
      
      this.deleteById({id:this.deId}).then((res)=>{
        this.page_query(this.obj)
        this.$notify({
        title: "成功",
        message: res.message,
        type: "success",
        })
        this.deId = ''
      })
      
      
    },
    change_page(val) {
      this.obj.page = val;
    },
    turnUpdate() {
      this.$router.push({
        path: "/data_list/updata",
      });
    },
  },
};
</script>